import type Response_Dto from "@/dto/response/Api_Result"
import { ElLoading, ElMessage } from "element-plus";

let loading: any;

/**
 * 启动全局加载
 * @param msg 
 */
export const start_loading = (msg?: string) => {
    loading = ElLoading.service({
        lock: true,
        text: msg || '请稍后...',
        background: 'rgba(0, 0, 0, 0.7)',
    })
}

/**
 * 关闭全局加载
 */
export const close_loading = () => {
    if (loading)
        loading.close();
}

/**
 * 消息提醒
 * @param response 
 */
export const notice = (response: Response_Dto) => {
    if (response.code === 0)
        ElMessage.success(response.message);
    else
        ElMessage.error(response.message);
}